package commRedis

import (
	"fmt"
	"github.com/go-redis/redis"
)

func SetRedisOptions(addr string, password string) {
	Options = &redis.Options{
		Addr:     addr,
		Password: password,
		DB:       0,
	}
}

func ConnectRedis() {
	Client = redis.NewClient(Options)
}

func TestConnect() bool {
	// 拦截可能产生的异常
	defer func() {
		if e := recover(); e != nil {
			fmt.Println("尚未初始化连接redis:", e)
		}
	}()

	pong := Client.Ping().Val()
	return pong == "PONG"
}
